import com.qtcm.nas.fyx.bendianpinglun.dao.IUserDao;
import com.qtcm.nas.fyx.bendianpinglun.pojo.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Demo01 {
    private InputStream in;
    private SqlSessionFactory factory;
    private SqlSession session;
    private IUserDao userDao;
    @Before
    public void init(){
        try {
            in = Resources.getResourceAsStream("SqlConfig.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder=new SqlSessionFactoryBuilder();
        factory = sqlSessionFactoryBuilder.build(in);
        session = factory.openSession();
        userDao = session.getMapper(IUserDao.class);
    }
    @Test
    public void findAll(){
        List<Student> all = userDao.findAll();
        for (Student student : all
                ) {
            System.out.println(student);
        }
    }
    @After
    public void after(){
        session.close();
        try {
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
